package gunfire.cards;

import basemod.abstracts.CustomCard;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.utility.WaitAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.vfx.combat.WeightyImpactEffect;
import gunfire.GunfireMod;
import gunfire.characters.Taizi;

import static gunfire.GunfireMod.makeCardPath;

public class Goshawk extends CustomCard {

    public static final String ID = GunfireMod.makeID(Goshawk.class.getSimpleName());
    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG = makeCardPath("Goshawk.png");
    private static final CardRarity RARITY = CardRarity.RARE;
    private static final CardType TYPE = CardType.ATTACK;
    private static final CardTarget TARGET = CardTarget.NONE;
    public static final CardColor COLOR = Taizi.Enums.COLOR_GRAY;
    private static final int COST = 3;

    public Goshawk() {
        super(ID, NAME, IMG, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET);
        this.baseDamage = 40;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgradeName();
            this.upgradeDamage(15);
        }
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        int maxHealth = -1;
        AbstractMonster maxHealthMonster = null;
        for (AbstractMonster mo : AbstractDungeon.getCurrRoom().monsters.monsters) {
            if (!mo.isDeadOrEscaped()) {
                if(mo.currentHealth > maxHealth){
                    maxHealth = mo.currentHealth;
                    maxHealthMonster = mo;
                }
            }
        }
        if(maxHealthMonster != null){
            this.addToBot(new VFXAction(new WeightyImpactEffect(maxHealthMonster.hb.cX, maxHealthMonster.hb.cY)));
            this.addToBot(new WaitAction(0.8F));
            this.addToBot(new DamageAction(maxHealthMonster, new DamageInfo(p, this.damage, DamageInfo.DamageType.NORMAL), AbstractGameAction.AttackEffect.BLUNT_HEAVY));
        }
    }

    @Override
    public AbstractCard makeCopy() {
        return new Goshawk();
    }
}
